package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SetmealMapper {
    /*
     * 根据分类id查询套餐数量
     * */
    @Select("SELECT count(id) FROM setmeal WHERE category_id = #{categoryId}")
    Integer getSetmealCountByCategoryId(Long categoryId);

    /*
    * 新增菜品
    * */
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);
    /*
    * 分页查询套餐
    * */
    Page<SetmealVO> pageSelect(SetmealPageQueryDTO setmealPageQueryDTO);

    /*
    * 根据分类ID修改套餐状态
    * */
    @Update("UPDATE setmeal SET status = #{status},update_time = #{updateTime},update_user = #{updateUser} WHERE category_id = #{categoryId}")
    void updateStatusByCategoryId(Long categoryId, Integer status, LocalDateTime updateTime, Long updateUser);

    @Select("SELECT * FROM setmeal WHERE id = #{id}")
    SetmealVO selectById(Long id);

    /*
    * 查询开启状态的套餐数量
    * */
    Integer selectOpenStatusSetmealCount(List<Long> ids, Integer status);
    /*
    * 批量删除套餐
    * */
    void deleteSetmeals(List<Long> ids);

    /*
    * 修改套餐
    * */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /*
    * 根据分类id查询套餐
    * */
    @Select("SELECT * FROM setmeal WHERE category_id = #{categoryId} AND status = #{status}")
    List<Setmeal> getSetmealByCategoryId(Integer categoryId,Integer status);

    @Select("SELECT COUNT(id) FROM setmeal WHERE status = #{status}")
    Integer getSetmealStatusCount(Integer status);
}
